home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
mysystem.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
2KB
|
64 lines
/*
* Copyright 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* mysystem -
* A rehacked and better system.
*
* Paul Haeberli - 1993
*/
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <sys/wait.h>
static char bin_shell[] = "/bin/sh";
static char shell[] = "sh";
static char shflg[]= "-c";
extern int _fork(), _execl();
int system(const char *s)
{
int status, pid, w;
struct sigaction oldistat;
int NewStyle;
NewStyle = 1;
if (s == NULL) return(1);
if (_sigaction(SIGINT,NULL,&oldistat) == -1) {
if (_oserror() == EINVAL)
NewStyle = 0;
else
return(-1);
}
if ((pid = _fork()) == 0) {
(void) _execl(bin_shell, shell, shflg, s, (char *)0);
_exit(127);
}
if (pid < 0) {
w = -1;
} else {
if (NewStyle) {
w = _waitpid(pid,&status,0);
} else {
while ((w = _wait(&status)) != pid && w != -1)
;
}
}
return((w == -1)? w: status);
}